#include <iostream>

#include "PKBStubForFollowTest.h"

PKBStubForFollowTest::PKBStubForFollowTest(void) {
	cout << "Constructing PKBStubForFollowTest\n";
}


PKBStubForFollowTest::~PKBStubForFollowTest(void) {
}

// Currently assumes the following SIMPLE source code:
// Procedure MyProc {
//1.	x = y;
//2.	y = z;
//3.	a = b;
//4.	b = c;
// }
const std::vector<int>& PKBStubForFollowTest::getLinesByEntity(Type::Entity::Line entityType) {
	std::vector<int> *lines = new std::vector<int>();
	/*if (entityType == PROG_LINE) {
		lines->push_back(1);
		lines->push_back(2);
		lines->push_back(3);
		lines->push_back(4);
		} else*/ if (entityType == Type::Entity::ASSIGNMENT_LINE_ENTITY) {
		lines->push_back(1);
		lines->push_back(2);
		lines->push_back(3);
		lines->push_back(4);
	} /*else if (entityType == STMT) {
		lines->push_back(1);
		lines->push_back(2);
		lines->push_back(3);
		lines->push_back(4);
	}*/
	return *lines;
}

// Assumes the following Follows relationships:
// Follows(1,2), Follows(2,3), Follows(3,4)
// e.g. getFollows(2) will return 3.
Type::Index::Line PKBStubForFollowTest::getFollows(Type::Index::Line index) {
	if (index == 1) return 2; // Follows(1,2)
	if (index == 2) return 3; // Follows(2,3)
	if (index == 3) return 4; // Follows(3,4)
	return -1; // No other follows relationships
}

// Assumes the following Follows relationships:
// Follows*(1,2), Follows*(1,3), Follows*(1,4) Follows*(2,3), Follows(2,4), Follows(3,4)
// e.g. getFollows(2) will return a vector [3, 4].
vector<int> PKBStubForFollowTest::getFollowStar(Type::Index::Line index) {
	vector<int> resultIndexes;
	if (index == 1) {
		resultIndexes.push_back(2);
		resultIndexes.push_back(3);
		resultIndexes.push_back(4);
	}
	if (index == 2) {
		resultIndexes.push_back(3);
		resultIndexes.push_back(4);
	}
	if (index == 3) {
		resultIndexes.push_back(4);
	}
	return resultIndexes;
}

// Assumes the following Follows relationships:
// Follows(1,2), Follows(2,3), Follows(3,4)
// e.g. getFollows(2) will return 1.
Type::Index::Line PKBStubForFollowTest::getFollowedBy(Type::Index::Line index) {
	if (index == 2) return 1;
	if (index == 3) return 2;
	if (index == 4) return 3;
	return -1;
}

// Assumes the following Follows relationships:
// Follows*(1,2), Follows*(1,3), Follows*(1,4) Follows*(2,3), Follows(2,4), Follows(3,4)
// e.g. getFollows(3) will return a vector [1, 2].
vector<int> PKBStubForFollowTest::getFollowedByStar(Type::Index::Line index) {
	vector<int> resultIndexes;
	if (index == 2) {
		resultIndexes.push_back(1);
	}
	if (index == 3) {
		resultIndexes.push_back(1);
		resultIndexes.push_back(2);
	}
	if (index == 4) {
		resultIndexes.push_back(1);
		resultIndexes.push_back(2);
		resultIndexes.push_back(3);
	}
	return resultIndexes;
}

// Assumes the following Follows relationships:
// Follows(1,2), Follows(2,3), Follows(3,4)
// e.g. isFollows(1,2) returns true, and isFollows(1,3) returns false.
bool PKBStubForFollowTest::isFollows(Type::Index::Line indexLeft,Type::Index::Line indexRight) {
	if (indexLeft == 1 && indexRight == 2) {
		return true;
	} else if (indexLeft == 2 && indexRight == 3) {
		return true;
	} else if (indexLeft == 3 && indexRight == 4) {
		return true;
	} else {
		return false;
	}
}

// Assumes the following Follows relationships:
// Follows*(1,2), Follows*(1,3), Follows*(1,4) Follows*(2,3), Follows*(2,4), Follows*(3,4)
// e.g. isFollowStar(1,3) returns true, and isFollowStar(2,1) returns false.
bool PKBStubForFollowTest::isFollowStar(Type::Index::Line indexLeft, Type::Index::Line indexRight) {
	if (indexLeft == 1) {
		if (indexRight >= 2 && indexRight <= 4) {
			return true;
		} else {
			return false;
		}
	} else if (indexLeft == 2) {
		if (indexRight >= 3 && indexRight <= 4) {
			return true;
		} else {
			return false;
		}
	} else if (indexLeft == 3) {
		if (indexRight == 4) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}